Skip to content

gh-161489: Make concurrent gi_frame test scheduling-independent - #161585

Open
localzet wants to merge 1 commit into
python:mainfrom
localzet:gh-161489-gi-frame-concurrent-test
Open

localzet wants to merge 1 commit into
python:mainfrom
localzet:gh-161489-gi-frame-concurrent-test

Conversation

@localzet

@localzet localzet commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix a scheduling race in TestFTGenerators.test_concurrent_gi_frame (gh-161489).

The test previously assumed the reader thread would observe the generator before the runner exhausted all 10,000 yields. Under --parallel-threads oversubscription the runner can finish first, leaving frames empty and causing AssertionError: 0 != 1 even though gi_frame is correct.

The test now uses two events to coordinate a first sample of a live generator after its first yield. The runner waits for that sample before advancing through the remaining values. Subsequent frame reads are still concurrent, and the existing len(frames) == 1 assertion remains unchanged: the test still detects unexpected frames or missing observations, rather than weakening the assertion to accept an unobserved run.

Only the test file changes; no interpreter/runtime or public API modifications.

Verification

On a CPython --with-pydebug --disable-gil build in my fork:

  • 80 consecutive runs of the targeted test: passed.
  • --parallel-threads=4 -j4 -m test_concurrent_gi_frame: passed.
  • Complete test_free_threading.test_generators module: passed (7 tests).

Run (free-threaded job): https://github.com/localzet/cpython/actions/runs/42410734206

The initial research workflow also attempted the module under a regular GIL build, where test.test_free_threading intentionally raises SkipTest when imported directly by unittest. I've removed that inapplicable job from the follow-up workflow and the free-threaded rerun is underway.

This is a tests-only PR, so skip news is appropriate (a maintainer may need to apply it).

localzet commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

This PR only fixes a test scheduling race in test_free_threading; it does not change runtime behavior. Could a maintainer please apply the skip news label? The bedevere/news check currently fails because the label is missing. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant